import Vue from 'vue';
import loadingModal from "../spinLoading"
const tableModal = Vue.extend(require('./tableModal.vue').default);
let modalList ={};
let modal = {
  showTableModal(options) {
    /**options
     * title :标题
     * width :宽度
     * closeable :是否显示关闭按钮
     * maskCloseable :点击遮罩是否关闭
     * okText: 确定按钮文字
     * cancenlText :取消按钮文字
     * labelWidth: 表单域标签的宽度 label文字宽度
     * 
     * **/
    if (typeof options != "object") return;
    
    if(options.el==undefined){
      options.el=document.getElementById("app");
    }
    let modalInstance = new tableModal({ propsData: {"column":options.info.columns,"list":options.info.list,"totalCnt":options.info.TotalCnt,"searchPageSize":options.info.searchPageSize,"searchPage":options.info.searchPage,"msg":options.info.msg,"title":options.info.title}});
    modalInstance.closeCallBack = this.hideTableModal;
    modalInstance.vm = modalInstance.$mount()
    modalInstance.vm.$on('pageChange', (data)=> {
      if(options.pageChange!=undefined){
        options.pageChange(data);
      }
    })
    options.el.appendChild(modalInstance.vm.$el)
    Vue.nextTick(() => {
      modalInstance.modalIsShow = true;
      loadingModal.close()
    });
    modalList[modalInstance._uid] = {"parent":options.el,"child":modalInstance}
    return modalInstance._uid
  },
  hideTableModal(_index) {
    setTimeout(() => {
      let obj = modalList[_index];
      obj.parent.removeChild(obj.child.vm.$el);
      obj.child.$destroy();
      modalList[_index] = null
      delete(modalList[_index])
    }, 200);
  },
  reloadTableModal(_index){
    let obj = modalList[_index];
    obj.child._reloadForm();
  },
  closeTableModal(_index) {
    let obj = modalList[_index];
    if(obj==undefined||obj==null) return;
    this.hideTableModal(_index);
  }
}
export default modal; 